package com.iot.ammeter.ui.components

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import com.iot.ammeter.R
import com.iot.ammeter.common.timestampToDateTime
import com.iot.ammeter.model.entry.BalanceFillRecord


/**
 * 充值记录 - 列表
 */
@Composable
internal fun FillRecords(
    records: List<BalanceFillRecord>,
) = Column(
    Modifier.padding(0.dp, 10.dp),
) {
    Text(
        text = stringResource(id = R.string.balance_fill_records),
        style = MaterialTheme.typography.titleMedium,
        modifier = Modifier
            .padding(0.dp, 0.dp, 0.dp, 10.dp)
            .fillMaxWidth(),
        fontWeight = FontWeight.Medium,
        color = MaterialTheme.colorScheme.onBackground
    )
    if (records.isEmpty()) {
        FillRecordNoData()
    } else LazyColumn {
        items(records) { record ->
            FillRecordCard(
                arrayOf(
                    timestampToDateTime(record.fillTime),
                    String.format("%.2f", record.fillAmount),
                    stringResource(id = record.payment.resId)
                )
            )
        }
    }
}